package com.briup.sms.service.impl;

import com.briup.sms.dao.BannerMapper;
import com.briup.sms.entity.Banner;
import com.briup.sms.service.BannerService;
import com.briup.sms.utils.ResultCode;
import com.briup.sms.utils.SMSException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author :xuyang
 * @DateTime:2023/12/26 9:11
 * @Version :v1.0.0
 * ClassName:BannerServiceImpl
 * Package  :com.briup.sms.service.impl
 * Description:TODO
 */
@Service
public class BannerServiceImpl implements BannerService {
    @Autowired
    BannerMapper mapper;

    @Override
    public PageInfo<Banner> findBanners(String title, Boolean active, Integer pageSize, Integer pageNum) {
        List<Banner> List = mapper.findBanners(title, active);
        PageInfo<Banner> pageInfo = new PageInfo<>(List);
        return pageInfo;
    }

    @Override
    public void save(Banner banner) {
        //根据banner对象的id是否为空 决定操作
        if (banner.getId() == null) {
            mapper.insertBanner(banner);
        } else {
            mapper.updateBanner(banner);
        }
    }

    @Override
    public void updateActive(Integer id) {
        //先查id对应的banner对应的信息
        Banner banner = mapper.findById(id);
        //将启用状态取反
        boolean b = !banner.getActive();
        //赋值给当前对象的启用状态
        banner.setActive(b);
        //更新轮播对象信息
        mapper.updateBanner(banner);
    }


}
